<%@ page contentType="text/html;charset=UTF-8" trimDirectiveWhitespaces="true"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<c:set var="extLibs" value="validate,grid"/>
<sys:header title="疗休养申请管理 - ${restApply.isNewRecord ? '新增' : '编辑'}疗休养申请" extLibs="${extLibs}"/>
<link href="${ctxStatic}/common/css/form.css" rel="stylesheet" type="text/css">

<div class="portlet box ${boxStyleColor} autoHeight">
	<div class="portlet-body form">
		<form:form id="inputForm" modelAttribute="restApply" action="${ctx}/rst/restApply/save" method="post" class="form-horizontal">

			<div class="tool">
				<c:if test="${restApply.isNewRecord}">
					<input id="btnSubmit" type="button" value="提交" class="tool1">
				</c:if>
				<input id="btnCancel" type="button" value="关闭" class="tool1" onclick="closeCurrentTabPage('${param.parentTabPageId}')">
			</div>
			<div class="biaodan_bg">
				<div class="biaodan">
					<table width="100%" border="0" class="tb2">
						<tr>
							<td colspan="8" align="center"  ><strong style="font-size:24px; font-weight:normal;">${fns:getConfig('university')}疗休养申请表</strong></td>
						</tr>
					</table>
						<table width="100%" border="0" class="tb4">

							<form:hidden path="id"/>
							<form:hidden path="billType" value="XY"/>
							<form:hidden path="approveStatus"/>

							<tr>
								<td  width="100" class="text-center" bgcolor="#f5f5f5">姓名</td>
								<td width="120">
									<form:hidden path="memberCode"/>
									<form:input path="memberName" htmlEscape="false" maxlength="64" class="form-control required"/>
								</td>
								<td  width="100" class="text-center" bgcolor="#f5f5f5">性别</td>
								<td width="120">
									<form:select path="sex" multiple="false" class="form-control required input-sm"  >
										<form:options items="${fns:getDictList('sex')}" itemLabel="name" itemValue="value" htmlEscape="false"/>
									</form:select>
								</td>
								<td  width="100" class="text-center" bgcolor="#f5f5f5">年龄</td>
								<td width="120">
									<form:input path="age" htmlEscape="false" maxlength="64" class="form-control required"/>
								</td>
								<td  width="100" class="text-center" bgcolor="#f5f5f5">分工会</td>
								<td width="120">
									<form:hidden path="officeCode"/>
									<form:input path="officeName" htmlEscape="false" maxlength="64" class="form-control required"/>

								</td>
							</tr>



							<tr>
								<td  width="100" class="text-center" bgcolor="#f5f5f5">职务</td>
								<td width="120">
									<form:input path="duty" htmlEscape="false" maxlength="64" class="form-control required"/>
								</td>
								<td  width="100" class="text-center" bgcolor="#f5f5f5">手机</td>
								<td width="120">
									<form:input path="phone" htmlEscape="false" maxlength="64" class="form-control required"/>

								</td>
								<td  width="100" class="text-center" bgcolor="#f5f5f5">线路</td>
								<td width="120">
									<form:hidden path="lineName"/>

									<form:select path="lineCode" multiple="false" cssClass="form-control" class="form-control  input-sm" onchange="">
										<%--<form:option value=""></form:option>--%>
										<form:options items="${lineList}"  itemLabel="lineName" itemValue="lineCode" htmlEscape="false"></form:options>
									</form:select>
								</td>
								<td  width="100" class="text-center" bgcolor="#f5f5f5">出发校区</td>
								<td width="120">
									<form:select path="campus" multiple="false" class="form-control required input-sm"  >
										<form:options items="${fns:getDictList('campus')}" itemLabel="name" itemValue="value" htmlEscape="false"/>
									</form:select>
								</td>
							</tr>
							<tr>
								<td class="text-center" bgcolor="#f5f5f5">申请理由</td>
								<td colspan="7">
									<form:textarea path="reason" htmlEscape="false" rows="8" maxlength="200" class="form-control required input-sm"/>
								</td>
							</tr>
							<c:if test="${restApply.approveStatus>1}">
							<tr>
								<td class="text-center" bgcolor="#f5f5f5">分工会审批意见</td>
								<td colspan="7">
									<form:textarea path="approveMemo1" htmlEscape="false" rows="8" maxlength="200" class="form-control required input-sm"/>
								</td>
							</tr>


							</c:if>

							<c:if test="${restApply.approveStatus==4||restApply.approveStatus==5}">
								<tr>
									<td class="text-center" bgcolor="#f5f5f5">校工会审批意见</td>
									<td colspan="7">
										<form:textarea path="approveMemo2" htmlEscape="false" rows="8" maxlength="200" class="form-control required input-sm"/>
									</td>
								</tr>

							</c:if>

						</table>


						<h4 class="form-section">随行人员</h4>
						<div class="ml10 mr10">
							<table id="dataGrid"></table>
							<a href="#" id="aaa" class="btn btn-primary mt10 mb10"><i class="fa fa-plus"></i> 增行</a>

						</div>
						<div class="hide">
							<input type="hidden" id="flowId" name="flowId"/>
							<sys:listselect id="approval" name="approvalCode" value="" labelName="approvalName" labelValue=""
											boxHeight="500"	boxWidth="450" returnCodeAttr="userCode" returnNameAttr="userName"	title="审批人" url="" multiple="true" cssClass="form-control"  />
						</div>
				</div>
			</div>


		</form:form>
	</div>
</div>
<sys:footer extLibs="${extLibs}"/>
<script type="text/javascript">

	$("#inputForm").validate({
		submitHandler: function(form){
			$("#lineName").val($("#lineCode").select2("data").text);

			ajaxSubmitForm($(form), function(data){
				showMessage(data.message);
				if(data.result == Global.TRUE){
					closeCurrentTabPage('${param.parentTabPageId}', function(contents, contentWindow){
						contentWindow.page();
					});
				}
			}, "json");
	    }
	});
	$('#btnSubmit').click(function(){
		<%--$.post("${ctx}/eflow/flowTemplate/getFirstStep",--%>
			<%--{"billType":$("#billType").val(),--%>
			 <%--"companyCode":$("#officeCode").val(), --%>
			 <%--"officeCode":$("#officeCode").val(),--%>
			 <%--"applicantCode":$("#memberCode").val(),--%>
			 <%--"billAmt":$("#billAmt").val()},--%>
			<%--function(data){--%>
				<%--if(data.result  == Global.FALSE){--%>
					<%--showMessage(data.message);--%>
				<%--}else{--%>
					<%--$("#flowId").val(data.firstStep.flowId);--%>
					<%--// 指定到人，弹出审批人选择界面--%>
					<%--if(data.firstStep.isFixApproval){--%>
						<%--var url = "${ctx}/eflow/flowBusiness/approvalSelect?flowTemplatesId="+data.firstStep.id;--%>
						<%--$("#approvalDiv").attr("data-url",url);--%>
						<%--$("#approvalName").click();--%>
					<%--} else if(data.firstStep.approvalType == "1"){--%>
						<%--// 不指定人，直接提交--%>
						<%--$("#inputForm").submit();--%>
					<%--}--%>
					<%----%>
				<%--}--%>
			<%--},"json"--%>
		<%--)--%>
		var dg = $('#dataGrid');
		updateListFieldName(dg, 'retinueList', 'name');
		updateListFieldName(dg, 'retinueList', 'sex');
		updateListFieldName(dg, 'retinueList', 'phone');
		updateListFieldName(dg, 'retinueList', 'idNo');

		$("#inputForm").submit();

	});
		

	function approvalCallbackForMap(dataMap, v, h, f){
		$.each(dataMap, function(key, value){
			$("#approvalCode").val(value.userCode);
		})
		var dg = $('#dataGrid');
		updateListFieldName(dg, 'retinueList', 'name');
		updateListFieldName(dg, 'retinueList', 'sex');
		updateListFieldName(dg, 'retinueList', 'phone');
		updateListFieldName(dg, 'retinueList', 'idNo');
		$("#inputForm").submit();
	}

	$("#aaa").click(function(){
		$('#dataGrid').dataGrid('getParam','onSelectRow')('new');
	});
	//初始化业务数据子表DataGrid对象
	$("#dataGrid").dataGrid({

		data: ${fns:toJson(retinueList)},
		datatype: "local", // 设置本地数据
		autoGridHeight: function(){return 'auto'}, // 设置自动高度

		// 设置数据表格列
		columnModel: [
			{header:'姓名', name:'name', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control required'}},
			{header:'性别', name:'sex', index:'a.sex', width:100,
				formatter: function(val, obj, row, act){
					return getDictLabel(${fns:getDictListJson('sex')}, val, '未知', true);
				},
				editable: true, edittype: "select", editoptions: {'class': 'form-control required',
					items: $.merge([{label:'&nbsp;',value:''}], ${fns:getDictListJson('sex')}),
					itemLabel: 'label', itemValue: 'value', dataInit: function(element){
						$(element).select2().on("change",function(){try{$(this).valid();}catch(e){}});
					}
				}
			},
			{header:'联系方式', name:'phone', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control required'}},
			{header:'身份证号', name:'idNo', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control required'}},
			{header:'操作', name:'actions', width:80, sortable:false, fixed:true, formatter: function(val, obj, row, act){
					var actions = [];
					actions.push('<a href="#" onclick="confirmx(\'你确认要删除这条数据吗？\', function(){$(\'#dataGrid\').dataGrid(\'delRowData\',\''+obj.rowId+'\')});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');

					return actions.join('');
				}, editoptions: {defaultValue: 'new'}}
		],

		// 编辑表格参数
		editGrid: true,				// 是否是编辑表格
		editGridInitRowNum: 1,		// 编辑表格的初始化新增行数
		editGridAddRowBtn: $('#aaa'),	// 子表增行按钮
		editGridAddRowInitData: {id: '', status: Global.STATUS_NORMAL},	// 新增行的时候初始化的数据

		ajaxSuccess: function(data){ // 加载成功后执行方法

		}
	});
	//提交前更新列表字段名字，以方便后台接受
	function updateListFieldName(dg, listName, fieldName){
		dg.find('[name$="'+fieldName+'"]:not(div,a)').each(function(key, val){
			$(this).attr('name',listName + '['+key+'].' + fieldName);
		});
	}
</script>